/**
 * 产品质量追溯查询
 */
$(document).ready(function () {
    // 查询
    $("#search").click(function () {
        searchProduct(); //要触发的方法
        return false;
    });

    //回车事件
    $(document).keydown(function (event) {
        var code = event.which;
        if (code == 13) {
            searchProduct(); //要触发的方法
        }
    });

    //登录按钮
    $("#login").click(function () {
        location.href = basePath + "login.jsp";
    });
});

function searchProduct() {
    var productCode = $("#productCode").val();
    $.ajax({
        url: basePath + "trace/search.action?productCode=" + productCode,
        type: "post",
        dataType: "json",
        success: function (data) {
            var traceInfo = $("#traceInfo");
            traceInfo.empty();
            var html = '';
            var productionList = data.productionList;//生产信息
            if (productionList != null && productionList.size > 0) {
                html += '<p style="font-weight:bold;font-size: 20px; ">生产：</p>';
                for (var i = 0; i < productionList.size; i++) {
                    html += productionList[i];
                }
            }
            var storageInfo = data.storageInfo;//入库信息
            if (storageInfo != null && storageInfo != undefined && storageInfo != "") {
                html += '<p style="font-weight:bold;font-size: 20px; ">入库：</p>';
                html += storageInfo;
            }
            var outStoreInfo = data.outStoreInfo;//出库信息
            if (outStoreInfo != null && outStoreInfo != undefined && outStoreInfo != "") {
                html += '<p style="font-weight:bold;font-size: 20px; ">出库：</p>';
                html += outStoreInfo;
            }
            var logisticsInfo = data.logisticsInfo;//物流信息
            if (logisticsInfo != null && logisticsInfo != undefined && logisticsInfo != "") {
                html += '<p style="font-weight:bold;font-size: 20px; ">物流：</p>';
                html += logisticsInfo;
            }
            var repairList = data.repairList;//维修信息
            if (repairList != null && repairList.size > 0) {
                html += '<p style="font-weight:bold;font-size: 20px; ">维修：</p>';
                for (var j = 0; j < repairList.size; j++) {
                    html += repairList[j];
                }
            }
            var errorInfo = data.errorInfo;//错误信息
            if (errorInfo != null && errorInfo != undefined && errorInfo != "") {
                html += '<p style="font-weight:bold;font-size: 20px; ">错误：</p>';
                html += errorInfo;
            }
            traceInfo.html(html);
        }
    });
}